import datetime
from weather.config import weather_config
from .modules import module_entity
from push import app
from push.gt_push import gt_push, get_token
import time


@app.task
def cron_push(module):
    print(f'start cron push at: {datetime.datetime.now()}')

    start = time.time()
    push_all(module)
    end = time.time()
    
    print('cron push end')
    print('spend time is {}'.format(end - start))


def push_all(module):
    title, msg, intent = generate_push_content(module)
    auth_token = get_token()
    gt_push(title, msg, intent, auth_token)


def generate_push_content(module_name):
    cur_module= module_entity.get_module(module_name)
    return cur_module['title'], cur_module['content'], cur_module['intent']
